﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DataBase;

public partial class GetPassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet Ds = new DataSet();
        Ds = DataManager.FavoriteManager.Instance.GetFavorite();
        this.drop_Favorite.DataSource = Ds;
        this.drop_Favorite.DataBind();
        #region 測試
        //Label lb = new Label();
        //lb.Text = Ds.Tables[0].Rows[0][1].ToString();
        //Page.Form.Controls.Add(lb);
        #endregion 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //以使用者註冊時的我的最愛,Email來更新密碼
        DataSet ds = new DataSet();
        ds = DataManager.RegisterManager.Instance.GetRegisterDataByEmailAndFavorite(txt_UserName.Text.Trim(),txt_Favorite.Text.Trim(),txt_Email.Text.Trim());
        if (ds.Tables[0].Rows.Count == 1)
        {
            //更新密碼
            DataManager.RegisterManager.Instance.UpdateUserPassword(txt_UserName.Text.Trim(),txt_Favorite.Text.Trim(),txt_Email.Text.Trim(),txt_NewPassword.Text.Trim());
        }
        else
        { 
            //提示輸入的我的最愛或Email有錯
            Response.Write("<script>alert('您的我的最愛或Email有錯誤')</script>");
        }
        #region 測試
        //if(ds.Tables[0]!=null){
        //Label lb = new Label();
        //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //{
        //    for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
        //    {
        //        lb.Text += ds.Tables[0].Rows[i][j].ToString();
        //    }
        //}
        //lb.Text += "\n";
        //lb.DataBind();
        //Page.Form.Controls.Add(lb);
        //txt_NewPassword.Text = ds.Tables[0].Rows[0][0].ToString();
        //txt_NewPassword.DataBind();
        //}
        #endregion
    }
}